package com.koocloud.electroplatemanage.controller;

import com.koocloud.electroplatemanage.common.pojo.ResponseTemplate;
import com.koocloud.electroplatemanage.pojo.WorkProcessVo;
import com.koocloud.electroplatemanage.service.WorkProcessService;
import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @program: Information_platform
 * @description: 主要工道及其过程记录控制层
 * @author: xxc
 * @create: 2020-11-16 14:15
 */
@RestController
@RequestMapping("/workprocess")
public class WorkProcessController {
    static Logger log = Logger.getLogger("workprocess");

    @Autowired
    WorkProcessService workProcessService;

    /**
     *@Description: 通过工单号查询一条主要工道及其过程记录
     *@Param: [workOrderNumber]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/16
     */
    @RequestMapping(value = "/selectByWorkOrderNumber", method = RequestMethod.POST, name = "通过工单号查询一条主要工道及其过程记录")
    public ResponseTemplate selectByWorkOrderNumber(String workOrderNumber) {
        //通过工单号查询主要工道及其过程记录
        return workProcessService.selectByWorkOrderNumber(workOrderNumber);
    }

    /**
     *@Description: 添加模板
     *@Param: [workOrderNumber]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/16
     */
    @RequestMapping(value = "/selectByWorkOrderNumberTemplate", method = RequestMethod.POST, name = "添加时的模板")
    public ResponseTemplate selectByWorkOrderNumberTemplate(String workOrderNumber) {
        //通过工单号查询主要工道及其过程记录
        return workProcessService.selectByWorkOrderNumberTemplate(workOrderNumber);
    }

    /**
     *@Description: 对主要工道及其过程记录进行全表查询
     *@Param: [page, limit, workProcessVo]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/16
     */
    @RequestMapping(value = "/selectAllData", method = RequestMethod.POST, name = "对主要工道及其过程记录进行全表查询")
    public ResponseTemplate selectAllData(String page, String limit, WorkProcessVo workProcessVo) {
        //分页参数为空则赋值0
        if (!StringUtils.isNotEmpty(page)) {
            page = "0";
        }
        if (!StringUtils.isNotEmpty(limit)) {
            limit = "0";
        }
        //查询所有记录 分页
        return workProcessService.selectAllData(page,limit,workProcessVo);
    }

    /**
     *@Description: 新增一条数据
     *@Param: [request, workProcessVo]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/16
     */
    @RequestMapping(value = "/insert", method = RequestMethod.POST, name = "新增一条数据")
    public ResponseTemplate insert(HttpServletRequest request, @RequestBody  WorkProcessVo workProcessVo) {
        //获取创建人
        String userId = request.getHeader("userId");
        //插入一条记录
        return workProcessService.insert(workProcessVo,userId);
    }

    /**
     *@Description: 逻辑删除一条记录
     *@Param: [request, id, deleteFlag]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/16
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST, name = "逻辑删除一条记录")
    public ResponseTemplate delete(HttpServletRequest request, @RequestParam(name="id") String id, @RequestParam(name="deleteFlag") String deleteFlag) {
        //获取修改人
        String userId = request.getHeader("userId");
        //逻辑删除一条记录
        return workProcessService.delete(id,userId,deleteFlag);
    }

    /**
     *@Description: 修改一条主要工道及其过程记录
     *@Param: [request, workProcessVo]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/16
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST, name = "修改一条主要工道及其过程记录")
    public ResponseTemplate update(HttpServletRequest request,@RequestBody WorkProcessVo workProcessVo) {
        //获取修改人
        String userId = request.getHeader("userId");
        //修改一条记录
        return workProcessService.update(workProcessVo,userId);
    }


    /**
     *@Description: 生产结束确认
     *@Param: [workOrderNumber]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: xxc
     *@date: 2020/11/19
     */
    @RequestMapping(value = "/confirmEntryInfo", method = RequestMethod.POST, name = "生产结束确认")
    public ResponseTemplate confirmEntryInfo(HttpServletRequest request,String workOrderNumber){
        String userId = request.getHeader("userId");
        return workProcessService.confirmEntryInfo(workOrderNumber,userId);

    }

    /**
     *@Description: 生产完成确认
     *@Param: [workOrderNumber]
     *@return: com.koocloud.electroplatemanage.common.pojo.ResponseTemplate
     *@Author: wjx
     *@date: 2020/11/20
     */
    @RequestMapping(value = "/confirmCompletedInfo", method = RequestMethod.POST, name = "生产完成确认")
    public ResponseTemplate confirmCompletedInfo(HttpServletRequest request,String workOrderNumber){
        String userId = request.getHeader("userId");
        return workProcessService.confirmCompletedInfo(workOrderNumber,userId);

    }
}
